<template>
  <div>
    <tableTpl
      :data="data"
      :columns="columns"
      v-on:changeItem="changeItem"
      :tableLoading="loading"
    >
      <div slot="table_nav" v-if="current_index >= 3">
        <a-tabs type="card" @change="getData" v-model="paramsData.deptlevel">
          <a-tab-pane key="" tab="全部"> </a-tab-pane>
          <a-tab-pane key="2" tab="市级"> </a-tab-pane>
          <a-tab-pane key="3" tab="县级"> </a-tab-pane>
        </a-tabs>
      </div>
      <div
        slot="rightHtml"
        slot-scope="{ record }"
        class="flexLeft"
        v-if="current_index % 2 != 0"
      >
        <a-button
          @click="showPopup('tj', record)"
          :disabled="record.taskEnable != 1"
          type="link"
        >
          <span class="flexCon fontS20"> 是否通过 </span>
        </a-button>
      </div>
      <a-button
        @click="showPopup('look', record)"
        :disabled="record.taskEnable != 1"
        type="link"
        slot="rightHtml"
        slot-scope="{ record }"
        v-else
      >
        <span class="flexCon fontS20"> 查看意见 </span>
      </a-button>
    </tableTpl>
    <dynamic-form
      :formData="formData"
      :recordData="record"
      ref="dynamic"
      @confirm="getData()"
    />
    <popup
      ref="popup"
      title="提示"
      :count="popText"
      @confirm="popConfirm"
    ></popup>
  </div>
</template>

<script>
import dynamicForm from "../components/dynamicForm/dynamicForm.vue";
import popup from "../components/pop/popup.vue";
import tableTpl from "../components/tableTpl/tableTpl.vue";
import { mapState } from "vuex";
import { tasklist, ByInstanceId } from "@/api";
import { recom } from "@/assets/js/declare";
export default {
  components: {
    tableTpl,
    dynamicForm,
    popup,
  },
  provide() {
    return {
      leftList: recom,
    };
  },
  data() {
    return {
      data: [], //表格所需数据
      record: {}, // 当前行数据
      popText: "",
      paramsData: recom[0].child[0].dataType, // 接口参数
      current_index: recom[0].child[0].index,
      loading: false,
    };
  },
  created() {
    this.getData();
  },
  computed: {
    ...mapState(["columns", "formData"]),
  },
  methods: {
    changeItem(k) {
      this.paramsData = k.dataType;
      this.current_index = k.index;
      this.getData();
    },
    // 获取页面数据
    async getData() {
      this.loading = true;
      const res = await tasklist(this.paramsData);
      this.loading = false;
      if (res.code != 200) return;
      res.rows.forEach((i, k) => {
        i.key = k + 1;
      });

      console.log(res,'res')
      this.data = res.rows;
    },
    // 展示弹窗
    showPopup(type, record) {
      switch (type) {
        case "tj":
          this.record = record;
          this.$refs.dynamic.showForm();
          this.$store.dispatch("GET_USER_DATA", record.taskId);
          break;
        case "look":
          ByInstanceId(record.baseId, 1).then((res) => {
            this.popText =
              res.data.length > 0
                ? res.data[0].formHistoryDataDTO[1].value
                : "暂无";
          });
          this.$refs.popup.showPop();
          break;
        case "ch":
          this.popText = "是否确认撤回";
          this.$refs.popup.showPop();
          break;
      }
    },
    popConfirm() {
      console.log("点击确认");
      this.$refs.popup.hidePop();
    },
  },
};
</script>

<style scoped>
</style>